package com.example.loginpage

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RadioButton
import androidx.lifecycle.ViewModelProvider
import com.example.loginpage.InputUtil.DataViewModel
import com.example.loginpage.databinding.FragmentSettingBinding


class SettingFragment : Fragment() {
    private lateinit var binding: FragmentSettingBinding
    private lateinit var dataViewModel: DataViewModel
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentSettingBinding.inflate(layoutInflater,container, false)
        dataViewModel = ViewModelProvider(requireActivity())[DataViewModel::class.java]

        dataViewModel.chatType.observe(requireActivity()){
            when(it){
                "智谱清言" -> binding.ModelGroup.check(R.id.chatglm2)
                "轩辕大模型" -> binding.ModelGroup.check(R.id.xuanyuan)
                "Gemma" -> binding.ModelGroup.check(R.id.gemma)
                "LLaMa" -> binding.ModelGroup.check(R.id.llama3)
                else -> binding.ModelGroup.check(R.id.ernie4_0)
            }
        }
        binding.ModelGroup.setOnCheckedChangeListener { _, checkedId ->
            val checkedRadioButton = binding.ModelGroup.findViewById<RadioButton>(checkedId)
            val selectedModel = checkedRadioButton.text.toString()
            dataViewModel.setChatType(selectedModel)
        }

        return binding.root
    }

}